package jjn.carl.hashtable;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Jjn
 * @since 2023/7/3 14:40
 */
public class LeetCode349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        boolean[] numCount = new boolean[1001];
        for (int j : nums1) {
            numCount[j] = true;
        }
        Set<Integer> result = new HashSet<>();
        for (int j : nums2) {
            if (numCount[j]) {
                result.add(j);
            }
        }
        int[] res = new int[result.size()];
        int i = 0;
        for (Integer num : result) {
            res[i] = num;
            i++;
        }
        return res;
    }
    
    public static void main(String[] args) {
        int[] nums1 = new int[]{2, 3, 4, 4};
        int[] nums2 = new int[]{3, 4, 4, 5, 5};
        int[] intersection = new LeetCode349().intersection(nums1, nums2);
        System.out.println("Arrays.toString(intersection) = " + Arrays.toString(intersection));
    }
}
